dir="/mnt/nas/datasets/diction"
dates=("0808" 
"0811" "0812" "0813" "0814" "0815" 
"0818" "0819" "0820" "0821" "0822" 
"0825" "0826" "0827" "0828" "0829"
"0901" "0902" "0903" "0904" "0905"
"0908" "0909" "0910" "0911" "0912"
"0915" "0916" "0917")  # 正确的数组定义方式
categories=("coat" "leather" "sweater")

# 初始化一个关联数组来存储每个类别的总clo(diff)数量
declare -A category_pattern
declare -A category_furry
# declare -A category_pattern_total
# declare -A category_furry_total
category_pattern_total=0
category_furry_total=0

for category in "${categories[@]}"; do
    # 初始化当前类别的总和为0
    category_pattern[$category]=0
    category_furry[$category]=0

    for date in "${dates[@]}"; do

        # 如果是 leather 类别且日期大于 0825，则跳过
        if [[ "$category" == "leather" && "$date" > "0825" ]]; then
            continue  # 跳过这个日期，继续下一个
        fi

        pattern_dir="$dir"/"$category""$date"_img_clo_diff_pattern
        furry_dir="$dir"/"$category""$date"_img_clo_diff_furry
        bash restore.sh $pattern_dir
        bash restore.sh $furry_dir

        count1=$(grep -c "\.jpg" $pattern_dir/names.txt)
        count2=$(grep -c "\.jpg" $furry_dir/names.txt)
        # count3=$(grep -c "\.jpg" "$dir"/"$category""$date"_img_clo_diff/names.txt)

        # 累加到当前类别的总和中
        category_pattern[$category]=$((category_pattern[$category] + count1))
        category_furry[$category]=$((category_furry[$category] + count2))

        echo $category "Date: $date, category pattern count: $count"
        echo $category "Date: $date, category furry count: $count2"
        # echo $category "Date: $date clo(diff), JPG count: $count3"
        echo
    done
done    

# 输出每个类别的clo(diff)总数量
echo "---> Total clo(diff) counts per category: <---"
for category in "${categories[@]}"; do
    echo "$category pattern: ${category_pattern[$category]}"
    echo "$category furry: ${category_furry[$category]}"

    category_pattern_total=$(($category_pattern_total + ${category_pattern[$category]}))
    category_furry_total=$(($category_furry_total + ${category_furry[$category]}))
done

echo "---> Total counts per category: <---"
echo "total pattern: ${category_pattern_total}"
echo "total furry: ${category_furry_total}"
